//控制层 
app.controller('newtableController',function($scope,$http ,$controller, newtableService,sealSchoolService){
	
	$controller('baseController' , {$scope:$scope});	//继承
	$scope.status = -1;
	if(localStorage.status){
		$scope.status = localStorage.status;
	}else{
		location.href="../login.html";
	}
	
	$scope.entity={};
	$scope.entity.signimgurl = '';
	
	$scope.signImgArr = [];
    //上传视频
    $scope.uploadImg = function() { 
        var fd = new FormData();
        var file = document.querySelector('input[type=file]').files[0];
//        var file = $scope.myFile;
        fd.append('video', file); 
         $http({
              method:'POST',
              url:"../article/uploadVideo.do",
              data: fd,
              headers: {'Content-Type':undefined},
              transformRequest: angular.identity 
               })   
              .success( function (response){
			      // 上传成功的操作
                  $scope.signImgArr.push(response.videoResult); 
            		console.log( $scope.signImgArr);
            		$scope.entity.signimgurl = '';
            	  $scope.signImgArr.forEach((item)=>{
            		  if($scope.entity.signimgurl != null && $scope.entity.signimgurl != ""){
            			  $scope.entity.signimgurl= $scope.entity.signimgurl+'#'+item;            			  
            		  }else{
            			  $scope.entity.signimgurl= item;
            		  }
            		  
            	  })
            	  
              }); 

     }
    
    //删除合同
    $scope.delImg = function(index){
    	console.log(index);
    	$scope.signImgArr.splice(index,1);
    	$scope.entity.signimgurl = '';
    	$scope.signImgArr.forEach((item)=>{
    	  if($scope.entity.signimgurl != null && $scope.entity.signimgurl != ""){
  			  $scope.entity.signimgurl= $scope.entity.signimgurl+'#'+item;            			  
  		  }else{
  			  $scope.entity.signimgurl= item;
  		  }
  	  })

    }
	//查询实体
	$scope.findOne=function(id){
		newtableService.findOne(id).success(
			function(response){
				console.log(response)
				$scope.signImgArr = [];
				$scope.entity.signimgurl = '';
				if(response.signimgurl != null && response.signimgurl != ""){
					$scope.signImgArr = response.signimgurl.split("#")
					console.log($scope.signImgArr)
				}
				$scope.entity=response;
			}		
		);
	}
    
    
    
    			$scope.findAll=function(){
    				newtableService.findAll().success(
    				function(response){
    					$scope.list=response;
    				}
    				
    			);
    		}
    			//分页
    			$scope.findPage=function(page, rows){
    				newtableService.findPage(page,rows).success(
    						function(response){
    							$scope.list=response.rows;	//显示当前页数据
    							$scope.paginationConf.totalItems=response.total;	//更新总记录数
    						}
    				);
    			}
    			
    			//增加
    			$scope.save=function(){
    				var object=null; //方法名
    				if($scope.entity.id!=null){
    					object=newtableService.update($scope.entity);
    				}else{
    					//console.log($scope.entity);
    					object=newtableService.add($scope.entity);
    				}
    				
    				object.success(
    					function(response){
    						if(response.success){
    							$scope.reloadList();	//刷新
    						}else{
    							alert(response.message);
    						}
    					}	
    				);
    			}
    			

    			
    			//删除
    			$scope.dele=function(){
    				newtableService.dele($scope.selectIds);
    				if($scope.selectIds.length > 0){
    					//询问框
    					layer.confirm('确定要删除吗？', {
    					  btn: ['确定','取消'] //按钮
    					}, function(){
    						newtableService.dele($scope.selectIds).success(
    					function(response){
    						if(response.success){
    							layer.msg(response.message,function(){
									$scope.reloadList();
									},{icon: 1});
    						}else{
    							alert(response.message);
    						}
    					});			
    					}, function(){
    						layer.msg('已取消删除',{icon:2});
    					});
    				}else {
						layer.msg('未选择任何选项',{icon:2});
					}	
    			}
    			
    			$scope.searchEntity={};
    			//条件查询
    			$scope.search=function(page, rows){
    				if($scope.status != 0){
        				$scope.searchEntity.status = $scope.status;   
        				console.log($scope.searchEntity.status);
        			}
    				newtableService.search(page,rows,$scope.searchEntity).success(
    					function(response){
    						$scope.list=response.rows;	//显示当前页数据
							$scope.paginationConf.totalItems=response.total;	//更新总记录数
    					}		
    				);
    			}
    			
    			$scope.schoolList=[];   //读取分驾校名称
    			//读取分驾校名称
    			$scope.findSelectSchoolList=function(){
    				sealSchoolService.selectSchoolList().success(
    					function(response){
    						$scope.schoolList=response;
    						console.log($scope.schoolList);
    					}
    				);
    			}
    			
    	});